package com.manage.common.util.dataFunction;

import java.text.DecimalFormat;
import java.util.Random;

/**
 * 随机生成日期
 * @author duaiyu
 * @version V1.0
 * @date 2022/2/23
 * 来源：自研
 */
public class CreateDate {
    //获取年月日
    public static String getDate(){
        String date = year() + "-" + month() + "-" + dates();
        return date;
    }
    //随机生成年，最高位最大是2，最小是1
    public static String year(){
        double random = Math.random();
        DecimalFormat df = new DecimalFormat("0.000");
        String format = df.format(random).substring(2);
        Integer high = new Random().nextInt(2)+1;
        String year = high + format;
        return year;
    }

    //随机生成月
    public static String month(){
        Integer month = new Random().nextInt(12);
        String re = null;
        if (month < 10){
            re = "0"+month;
        }else {
            re = month.toString();
        }
        return re;
    }

    //天数不考虑月份的影响
    public static String dates(){
        Integer day = new Random().nextInt(30);
        String re = null;
        if (day < 10){
            re = "0"+day;
        }else {
            re = day.toString();
        }
        return re;
    }
}
